package com.googlecode.connectlet.crypto.cipher.jce;

import javax.crypto.Cipher;

import com.googlecode.connectlet.crypto.cipher.CipherFactory;

public class JceCipherFactory implements CipherFactory {
	private String algorithm;
	protected Cipher cipher;
	private int blockSize;

	public JceCipherFactory(String algorithm) {
		this.algorithm = algorithm;
		try {
			cipher = Cipher.getInstance(algorithm + "/ECB/NoPadding");
			blockSize = cipher.getBlockSize();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public int getBlockSize() {
		return blockSize;
	}

	@Override
	public JceEncipheror getEncipheror(byte[] key) {
		return new JceEncipheror(algorithm, key);
	}

	@Override
	public JceDecipheror getDecipheror(byte[] key) {
		return new JceDecipheror(algorithm, key);
	}
}